import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileSearch1 {
    public static void main(String[] args) {
        String folderPath = "C:\\Users\\ASUS\\Desktop\\慧科项目\\eks-backend\\eks-backend\\ai\\configmap"; // 文件夹路径
        String word1 = "http://"; // 第一个单词
        String word2 = "https://"; // 第二个单词

        checkWordsInFiles(folderPath, word1, word2);
    }

    public static void checkWordsInFiles(String folderPath, String word1, String word2) {
        File folder = new File(folderPath);
        if (!folder.isDirectory()) {
            System.out.println("指定的路径不是一个文件夹");
            return;
        }

        File[] files = folder.listFiles();
        if (files == null || files.length == 0) {
            System.out.println("文件夹中没有文件");
            return;
        }

        for (File file : files) {
            if (file.isFile()) {
                try {
                    Path filePath = Paths.get(file.getAbsolutePath());
                    for (String line : Files.readAllLines(filePath)) {
                        if (line.contains(word1) || line.contains(word2)) {
                            System.out.println("文件名: " + file.getName());
                            System.out.println("行内容: " + line);
                            System.out.println("-----------------------------");
                        }
                    }
                } catch (IOException e) {
                    System.out.println("读取文件时发生错误: " + e.getMessage());
                }
            }
        }
    }
}
